package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.mapper.SmsHomeRecommendSubjectMapper;
import com.mail.model.db.SmsHomeRecommendSubject;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsHomeRecommendSubjectApiImpl implements SmsHomeRecommendSubjectApi{


    @Autowired
    private SmsHomeRecommendSubjectMapper smsHomeRecommendSubjectMapper;

    @Override
    public void save(SmsHomeRecommendSubject smsHomeRecommendSubject) {
        smsHomeRecommendSubjectMapper.insert(smsHomeRecommendSubject);
    }

    @Override
    public void deleteSubject(List<Long> ids) {
        smsHomeRecommendSubjectMapper.deleteBatchIds(ids);
    }

    @Override
    public Page<SmsHomeRecommendSubject> getSubjectByPage(Long pageNum, Long pageSize, String subjectName, Integer recommendStatus) {
        Page<SmsHomeRecommendSubject> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsHomeRecommendSubject> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(subjectName),SmsHomeRecommendSubject::getSubjectName,subjectName)
                .eq(recommendStatus != null,SmsHomeRecommendSubject::getRecommendStatus,recommendStatus);
        Page<SmsHomeRecommendSubject> page1 = smsHomeRecommendSubjectMapper.selectPage(page,wrapper);
        return page1;
    }

    @Override
    public void updateSubject(Long id, Integer recommendStatus) {
        SmsHomeRecommendSubject smsHomeRecommendSubject = new SmsHomeRecommendSubject();
        smsHomeRecommendSubject.setId(id);
        smsHomeRecommendSubject.setRecommendStatus(recommendStatus);
        smsHomeRecommendSubjectMapper.updateById(smsHomeRecommendSubject);
    }

    @Override
    public void updateSortSubject(Long id, Integer sort) {
        SmsHomeRecommendSubject smsHomeRecommendSubject = new SmsHomeRecommendSubject();
        smsHomeRecommendSubject.setId(id);
        smsHomeRecommendSubject.setSort(sort);
        smsHomeRecommendSubjectMapper.updateById(smsHomeRecommendSubject);
    }
}
